<template>
  <div class="tab-bar-item" @click="itemClick">
    <div class="tab-bar-item-icon" v-if="!isActive">
      <slot name="tab-bar-item-icon"></slot>
    </div>
    <div v-else>
      <slot name="tab-bar-item-icon-active"></slot>
    </div>
    <div class="tab-bar-item-text" :style="activeStyle">
      <slot name="tab-bar-item-text"></slot>
    </div>
  </div>
</template>

<script>
export default {
  name: 'TabBarItem',
  props: {
    path: String,
    activeColor: {
      type: String,
      default: 'red',
    },
  },
  data() {
    return {
      // isActive: true,
    }
  },
  methods: {
    itemClick() {
      console.log('点击')
      this.$router.replace(this.path)
    },
  },
  computed: {
    // 计算属性 isActive
    isActive() {
      // 当前处于活跃的路由对象，path属性
      return this.$route.path.indexOf(this.path) !== -1
    },
    activeStyle() {
      // return 不能少呀
      return this.isActive ? { color: this.activeColor } : {}
    },
  },
}
</script>

<style lang="less" scoped>
.tab-bar-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  img {
    width: 35px;
    height: 35px;
  }
  .tab-bar-item-text {
    // color: deepPink;
  }
  .active {
    color: pink;
  }
}
</style>
